<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    
    </style>
</head>
<body>
    <form id="tt" action="" method="get" onsubmit="return check()">
        <table>
            <tr>
                <td>name:</td>
                <td><input type="text" name="name" placeholder="name" autofocus></td>
            </tr>
            <tr>
                <td><font color="red">*</font> password:</td>
                <td><input type="password" placeholder="password" name="password"></td>
            </tr>
            <tr>
                <td><input type="submit" value="submit"></td>
            </tr>
        </table>
        <p onclick="test(this)">This is a new <span>ttt</span> <span>zzzz</span> </p>
    </form>
</body>
<script>
    function check () {
        var frm = document.getElementById("tt");
        var inputs = document.getElementsByTagName("input");
        for(var i = 0,length = inputs.length;i<length;i++){
            if (inputs[i].type=="text" || inputs[i].type=="password") {
                var p_node = inputs[i].parentNode;
                var pre_node = p_node.previousElementSibling;
                var t = pre_node.innerText;
                alert(t);
                if (t.charAt(0)=='*') {
                    if (inputs[i].value=="") {
                        alert("can not be empty");
                    };
                };
            }
        }
        return false;
    }
    function test(obj) {
        console.info(obj.innerText);
    }
</script>
</html>